<%@page import="com.libweb.model.dto.Board"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    
<%!
	String getTitleString(Board board) {
		
		StringBuilder html = new StringBuilder(256);
		
		for (int i=0; i<board.getDepth(); i++) {
			html.append("&nbsp;&nbsp;");
		}
		
		if(board.getDepth() > 0) {
			html.append("<img src='/libweb/image/re.gif' />");
		}
	
		
		if(board.isDeleted()) {
			html.append("<span style='color:gray' ");
			html.append("onclick='\"alert('삭제된 글입니다.');\">");
			html.append(board.getTitle());
			html.append("(삭제된 글)");
			html.append("</span>");
		}else {
			html.append("<a href='javascript:viewboard(");
			html.append(board.getBoardNo());
			html.append(");'>");
			html.append(board.getTitle());
			html.append("</a>");
		}
		return html.toString();
}
%>
    
    
<!DOCTYPE html>

<html>
	<head>
		<meta charset="utf-8" />
		<title>게시물 목록</title>
		<link rel="Stylesheet" href="/libweb/styles/default.css" />
		<script type="text/javascript">
			function viewboard(boardno, pageno) {
				<%
					String pageNo = request.getParameter("pageno");
					if (pageNo == null || pageNo.length() == 0)
						pageNo = "1";
				%>
				
				<% if(session.getAttribute("loginuser") != null) { %>
				location.href = 'view.action?boardno=' + boardno + "&pageno=<%= pageNo %>";
				<% } else { %>
				location.href = "/libweb/account/loginform.action?returnuri=/libweb/board/view.action?boardno=" + boardno + "&pageno=<%= pageNo%>"; 
				<% } %>
			}
		</script>
	</head>
	<body>
	
		<% pageContext.include("/WEB-INF/views/include/header.jsp"); %>
		
		<div id="pageContainer">
			
			<div style="padding-top:25px;text-align:center">
	
				<input type="button" value="글쓰기" 
					style="width:300px;height:25px"
					onclick="location.href='writeform.action';" />
				<br /><br />
				
				<% List<Board> boards = (List<Board>)request.getAttribute("boards"); %>
				<% if(boards != null && boards.size() > 0) { %>
				<table border="1" align="center">
					<tr style="background-color:beige;height:25px">
						<th style="width:50px">번호</th>
						<th style="width:300px">제목</th>
						<th style="width:150px">작성자</th>
						<th style="width:120px">작성일</th>
						<th style="width:80px">조회수</th>
					</tr>
					<% for(Board board : boards) { %>
					<tr style="height:25px">
						<td style="text-align:center"><%= board.getBoardNo() %></td>
						<td style="text-align:left;padding:5px">
							<%= getTitleString(board) %>
						</td>
						<td style="text-align:center"><%= board.getWriter() %></td>
						<td style="text-align:center"><%= board.getRegDate() %></td>
						<td style="text-align:center"><%= board.getReadCount() %></td>
					</tr>			
					<% } %>
				</table>
				<% } else { %>
					<div style='text-align:center'>등록된 게시물이 없습니다.</div>
				<% } %>			
				<br /><br />				
				<%= request.getAttribute("pager").toString() %>	
			</div>
		</div>
	</body>
</html>













